﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.ServiceModel;
using BookClubIt.Processor;
using DTO = BookClubIt.DTO;

namespace BookClubIt
{
    public partial class invite : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            DTO.BookClub club = BookClubProcessorInstance.GetBookClubById(CID);
            Page.Title = "Invite friends to " + club.Name.ToString();
            lblClubName.Text = club.Name.ToString();
        }
        protected void lnkInviteFriends_Click(object sender, EventArgs e)
        {
            string EmailList = txtEmailList.Text;
            string[] split = EmailList.Split(',');
            DTO.Member member = MemberProcessorInstance.GetMemberById(CurrentUserId);
            try
            {
               

                foreach (string item in split)
                {
                    string email = split.ToString();
                    MailMessage mail = new MailMessage();
                    mail.Subject = "You've been invited!";
                    mail.Body = "<html><body><p>Hello "+item.ToString()+",</p><p>"+member.Email+" has invited to join their book club at <a href='http://www.bookclubit.com'>bookclubit</a>!<p><a href='http://www.bookclubit.com/bookclub/default.aspx?id="+ CID +"'>Click here</a> to view the club and join if you would like!<p><br/><p>Thanks,</p><p>Bookclubit.com</p></body></html>";
                    mail.IsBodyHtml = true;
                    mail.From = new MailAddress("noreply@bookclubit.com");
                    mail.To.Add(new MailAddress(item.ToString()));
                    var client = new SmtpClient("smtp.gmail.com", 587)
                    {
                        Credentials = new NetworkCredential("bookclubitmail@gmail.com", "Ratecom#1"),
                        EnableSsl = true
                    };
                    client.Send(mail);
                }

               
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
      

         }
       
    }
}